import { useEffect, useRef } from "react";


export function useScrollToBottom<T extends HTMLElement>() {

    const ref = useRef<T>(null)


    useEffect(() => {
        const mutationObserve = new MutationObserver((mutations: MutationRecord[]) => {
            console.log(11);

            if (mutations.length < 1) return;
            if (mutations[0].addedNodes.length > 0) {
                ref.current?.scrollTo(0, ref.current.scrollHeight);
            }
        });

        mutationObserve.observe(ref.current!, {
            childList: true
        });
        return () => {
            mutationObserve.disconnect();
        };
    }, []);

    return ref
}